package com.wyhello.tube4.spring.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.wyhello.tube4.pojo.User;
import com.wyhello.tube4.spring.model.LoginCheckingModel;


@Controller
public class LoginController {
	@Autowired
	private LoginCheckingModel loginCheckingModel;
	@RequestMapping("/login")
	public ModelAndView login(User user,HttpSession session){
		User u = loginCheckingModel.querylogin(user);
		if(u!=null){
			//把用户信息存放在session里
			session.setAttribute("user", u);
			return new ModelAndView("redirect:/index.jsp");
			//return new ModelAndView("redirect:/exchange/query.do");
		}else {
			return new ModelAndView("login","error","用户名或密码错误！！！");
		}
	}
	@RequestMapping("/exit.do")
	public String exit(HttpSession session){
		session.invalidate();
		return "login";
	}
	@RequestMapping("/user/updatepw.do")
	public String querypw(User user,HttpSession session){
		if(loginCheckingModel.updatepw(user)){
			session.setAttribute("user", user);
			return "success1";
		}else{
			return "error";
		}
	}
	/*public ModelAndView login(User user){
		Boolean log = loginCheckingModel.querylogin(user);
		if(log){
			return "index";
		}
		ModelAndView mav = new ModelAndView("index.jsp");
		return mav;
	}*/
}
